Finding the rank of a matrix